<?php

// 公共控制器

namespace core;

class Controller
{

    // 定义属性用于保存对象
    public $smarty;
    public function __construct()
    {
        // 使用Smarty
        include_once VENDOR_PATH . 'smarty/Smarty.class.php';

        // 实例化
        $this->smarty = new \Smarty();
        //设置Smarty
        $this->smarty->template_dir =APP_PATH.P.'/view/'.C.'/';
        $this->smarty->caching = false;                //开发阶段不缓存
        $this->smarty->cache_dir = APP_PATH .P. '/cache';
        $this->smarty->cache_lifetime = 120;
        $this->smarty->compile_dir = APP_PATH .P. '/template_c';
    }
    protected function assign($key,$value){
        //调用smarty实现
        $this->smarty->assign($key,$value);
    }
    
    protected function display($file){
        $this->smarty->display($file);
    }
    // 成功提示
    protected function success($msg,$a=A,$c=C,$p=P,$time=3){
        $refresh="Refresh:".$time.";url=".URL."?a=".$a."&c=".$c."&p=".$p;
        header($refresh);
        echo $msg;
        exit;
    }
    // 错误提示
    protected function error($msg,$a=A,$c=C,$p=P,$time=3){
        $refresh="Refresh:".$time.";url=".URL."index.php?a=".$a."&c=".$c."&p=".$p;
        header($refresh);

        echo $msg;
        exit;
    }

}
